home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-10 | 5.3 KB | 210 lines | [TEXT/ttxt] |
- --<<<
- /*
- What Memory Diff does
- ---------------------
- This tool allows you to see in some detail what changes have
- taken place in memory, by showing which classes have a different number
- of instances in memory.
-
- You will get output from memoryDiff like
-
- There are 4 more instances of Rect. There is a total of 14 instances.
- There are 1 more instances of TwoDShape. There are currently 18 instances.
- There are 1 more instances of Region. There are currently 23 instances.
- There are 1 more instances of RamStream. There are currently 2 instances.
-
- You will usually also see reports of things related to the compiler, like
- expressionxlist, callxexpression, ApplyTree, etc. These can usually be ignored.
- Also, there will always be at least 1 more instance of RamStream because
- MemoryDiff creates them.
-
- Note that this tool only tells about what is going on in the ScriptX heap
- among ScriptX objects, it does not show what is happening in the "system" heap
- (where large data chunks like bitmap data and such are stored).
- To get the bigger picture of memory (including system heap), use a tool like moo.sx.
-
- How to use the Memory Diff Tool
- -------------------------------
- This utility can be used in both 1.0 and 1.5
- First, you need to take a snap shot of memory. To do this
-
- global m := memorySnap ()
-
- This will remember the state of memory at that point in time.
- Then, at some later time when you want to see what has changed in
- memory
-
- memoryDiff m
-
- These calls are usually used paired together, but you can take several memorySnaps
- and then use memoryDiff with those snaps at different times.
-
- enjoy
- --jj
- */
-
- function memorySnap ->
- (
- garbageCollect()
-
- threadCriticalUp()
- local d := debug
- debug := new RamStream maxSize:30000
- memoryUsage 1000
- local t := debug
- debug := d
- threadCriticalDown()
-
- return t
- )
-
- function getNextWord args -> (
- if (findNthContext(args,@word)) then (
- local returnStr := CopyFromTo(args[1],args[3],args[4])
- args[3] := args[4] + 1
- args[4] := 10000000 -- arbitrarily large number
- return returnStr
- )
- else
- return empty
- )
-
- function memoryDiff memoryState ->
- (
- garbageCollect()
-
- threadCriticalUp()
- local d := debug
- debug := new RamStream maxSize:30000
- memoryUsage 1000
- local t := debug
- debug := d
- threadCriticalDown()
-
- seekFromStart t 0
- local len := readReady t
- local afterSnap := new string
- pipePartial afterSnap t len
-
- local counter := 1
- for i in afterSnap do
- (
- if ( i = 95 ) do
- afterSnap[counter] := 120
-
- counter := counter + 1
- )
- print "finished xing the afterSnap"
-
- seekFromStart memoryState 0
- len := readReady memoryState
- local beforeSnap := new string
- pipePartial beforeSnap memoryState len
-
- counter := 1
- for i in beforeSnap do
- (
- if ( i = 95 ) do
- beforeSnap[counter] := 120
-
- counter := counter + 1
- )
- print "finished xing the beforeSnap"
-
- local objectKind
- local numInstances
- local beforeSnapList := new keyedlinkedList
-
- counter := 25
- local args := #(beforeSnap,counter,0,1000000) as Quad
- objectKind := (getNextWord(args)) as String
- repeat while (objectKind != empty AND objectKind != "Found") do
- (
- args[2] := 1
- numInstances := (getNextWord(args)) as integer
-
- add beforeSnapList objectKind numInstances
-
- args[2] := 3
- objectKind := (getNextWord(args)) as String
-
- if (objectKind = "struct") do
- (
- args[2] := 1
- objectKind := (getNextWord(args)) as String
- )
-
- )
- print "finished parsing the beforeSnap"
-
- local oldNumber
- local caption
-
- counter := 25
- args := #(afterSnap,counter,0,1000000) as Quad
- objectKind := (getNextWord(args)) as String
- repeat while (objectKind != empty AND objectKind != "Found") do
- (
- args[2] := 1
- numInstances := (getNextWord(args)) as integer
-
- oldNumber := beforeSnapList[objectKind]
-
- if (oldNumber = empty) then
- (
- caption := ("There are " + (numInstances as String) + " more instances of " \
- + objectKind + ". There are currently " + (numInstances as String) + " instances.") as String
- print caption
- )
- else if (oldNumber < numInstances) then
- (
- caption := ("There are " + ((numInstances - oldNumber) as String) + " more instances of "\
- + objectKind + ". There are currently " + (numInstances as String) + " instances.") as String
- print caption
-
- deleteKeyOne beforeSnapList objectKind
- )
- else if (oldNumber > numInstances) then
- (
- caption := ("There are " + ((oldNumber - numInstances) as String) + " fewer instances of " \
- + objectKind + ". There are currently " + (numInstances as String) + " instances.") as String
- print caption
-
- deleteKeyOne beforeSnapList objectKind
- )
- else
- deleteKeyOne beforeSnapList objectKind
-
- args[2] := 3
- objectKind := (getNextWord(args)) as String
-
- --print objectKind
-
- if (objectKind = "struct") do
- (
- args[2] := 1
- objectKind := (getNextWord(args)) as String
- )
-
- )
-
-
- if (beforeSnapList.size > 0) do
- (
- foreachBinding beforeSnapList ( key value ->
- (
- caption := ("There are " + (value as String) + " fewer instances of " \
- + key + ". There are currently 0 instances.") as String
- print caption
- ) ) undefined
-
- emptyout beforeSnapList
- )
-
- print "**"
- print "** use allInstances to get the actual instances of the mentioned classes. **"
- print "**"
- )
-
- -->>>
-